{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "d0021148",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['e', 'l', 'l']\n"
     ]
    }
   ],
   "source": [
    "## 查找常用字符串\n",
    "from typing import List\n",
    "class Solution:\n",
    "    def commonChars(self,words:List[str]) -> List[str]:\n",
    "        if not words :return []\n",
    "        result = []\n",
    "        harsh = [0]*26\n",
    "        count = 0\n",
    "\n",
    "        for i in words[0]:\n",
    "            harsh[ord(i) - ord('a')] += 1\n",
    "\n",
    "        for w in range(1,len(words)):\n",
    "            harshOther = [0]*26\n",
    "\n",
    "            for j in words[w]:\n",
    "                harshOther[ord(j) - ord('a')] += 1\n",
    "            \n",
    "            for k in range(26):\n",
    "                harsh[k] = min(harsh[k],harshOther[k])\n",
    "\n",
    "        while count < 26:\n",
    "            if harsh[count] != 0:\n",
    "                result.extend((chr(count + ord('a'))) * harsh[count])  # 这里题目要求返回的字符中可以重复，故而使用extend\n",
    "            count += 1\n",
    "        return result\n",
    "    \n",
    "if __name__ == \"__main__\":\n",
    "    words_list = [\"bella\",\"label\",\"roller\"]\n",
    "\n",
    "    sol = Solution().commonChars(words_list)\n",
    "    print(sol)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "env_py38",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
